<?php
/**
 * Created by PhpStorm.
 * User: apple
 * Date: 2020/10/18
 * Time: 3:23 PM
 */
namespace app\admin\controller;

use app\admin\logic\OrgLogic;
use app\BaseController;
use app\model\User;
use think\App;
use think\facade\Request;

class Organization extends BaseController
{

    public function __construct()
    {

        if(intval(config('user')['position']) !== User::SYS_ADMIN)   fail('暂无权限');
    }

    /*
     * 列表
     */
    public function index()
    {
        $orgLogic = new OrgLogic();
        success($orgLogic->getList());
    }
    /*
     * 添加组织
     * 默认添加一个组织管理员
     */
    public function create()
    {
        $orgLogic = new OrgLogic();
        success($orgLogic->addOrg());
    }
    /*
     * 修改
     */
    public function update()
    {
        $orgLogic = new OrgLogic();
        success($orgLogic->updateOrg());
    }
    /*
     * 启用或者禁用
     */
    public function close()
    {
        $param = Request::post();
        if(!isset($param['orgId']) || empty($param['orgId']))   fail('请选择组织');
        $orgId = intval($param['orgId']);

        if(!isset($param['orgStatus']))   fail('请选择操作状态');
        $orgStatus = intval($param['orgStatus']);

        $orgLogic = new OrgLogic();
        success($orgLogic->close($orgId,$orgStatus));
    }

    public function change()
    {

        $param = Request::get();
        if(!isset($param['orgid']) || empty($param['orgid']))   fail('请选择组织');
        $orgId = intval($param['orgid']);

        $orgLogic = new OrgLogic();
        success($orgLogic->change($orgId));
    }

}